/***************************************************************************
 *  Filename: navadatareceiver.h
 *  Class: NavaDataReceiver
 *  
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/


#ifndef NAVADATARECEIVER_H
#define NAVADATARECEIVER_H

#include <QObject>
#include <QUdpSocket>
#include <QHostAddress>
#include <QMutex>
#include <QWaitCondition>
#include <QByteArray>
#include <QList>
#include <QTimer>
#include "messages.h"
#include "logger.h"

class NavDataReceiver : public QObject
{
    Q_OBJECT
public:
    explicit NavDataReceiver(QObject *parent = 0);
    ~NavDataReceiver();
signals:
    void stopped();
    void timedout();
    void updateState(uint state);
    void updateAngleData(float roll, float pitch, float yaw);
    void updateVelocities(float vx, float vy, float vz);
    void logData(float roll, float pitch, float yaw, float vx, float vy, float vz, qint32 altitude);
    void updateAltitude(float altitude);
    void initSequence(int step);

public slots:
    void startRunning();
    void initializate();
    void newFileName(QString filename);
    void desiredValues(float roll, float pitch, float yaw, float gaz);
private slots:
    void readData();

private:
    quint32 dronestate;
    QUdpSocket *receiverSocket;
    QMutex mutex;
    QWaitCondition waitCondition;
    bool abort;
    QList<QByteArray> datagram;
    int firmware;
    QTimer timer;
    QTime timekeeper;
    bool droneresponded;
    bool booting;
    uint sequence;
    Logger logger;
};

#endif // NAVADATARECEIVER_H
